# 简化版同步构建脚本
$REMOTE_SERVER = "root@192.168.50.160"
$REMOTE_PATH = "/home/chenhg/gitee/xsan"

Write-Host "同步代码到远程服务器..." -ForegroundColor Green
ssh $REMOTE_SERVER "mkdir -p $REMOTE_PATH"

# 列出要同步的文件和目录（避免使用通配符）
$filesToSync = @(
    "src",
    "include",
    "docs",
    "tests",
    "tools",
    "CMakeLists.txt",
    "Makefile",
    "README.md"
)

# 逐个同步文件和目录
foreach ($item in $filesToSync) {
    if (Test-Path $item) {
        Write-Host "Syncing $item..." -ForegroundColor Cyan
        scp -r $item "$REMOTE_SERVER`:$REMOTE_PATH/"
    } else {
        Write-Host "Warning: $item not found, skipping" -ForegroundColor Yellow
    }
}

Write-Host "在远程服务器构建..." -ForegroundColor Green
ssh $REMOTE_SERVER "cd $REMOTE_PATH; rm -rf build; mkdir -p build; cd build; cmake ..; make -j4 > /tmp/build.log 2>&1"

Write-Host "检查编译错误..." -ForegroundColor Yellow
ssh $REMOTE_SERVER "cat /tmp/build.log | grep -E 'error:|warning:' || echo '没有发现编译错误或警告'" 